<?php

namespace App\Admin\Controllers\Commodity;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Illuminate\Http\Request;
use App\Model\Commodity_size;

class ApiSizeController extends Controller
{
    use ModelForm;
    public function get_size(Request $request)
    {
        $data = $request->input();
        if (empty($data) || empty($data["commodity_id"]))
            return return_array(1, '非法参数');
        $size = new Commodity_size();
        if(!empty($size = $size->get_size_by_commodity_id($data["commodity_id"])))
            return return_array(0,'yes', $size);
        else
            return return_array(1,'未知错误');
    }
    public function add_size(Request $request)
    {
        $data = $request->input();
        if (empty($data) || empty($data["commodity_id"]))
            return return_array(1, '非法参数');

        $data = array(
            'commodity_id' => $data['commodity_id'],
            'commodity_size_name'=>$data['name'],
        );
        $size = new Commodity_size();
        if(!empty($size->add_size($data)))
            return return_array(0,'yes', $size->get_size_by_commodity_id($data["commodity_id"]));
        else
            return return_array(1,'未知错误');
    }
}
